//
//  LGWeekdayCalendarCell.m
//  LGSanofiPatient
//
//  Created by 1234 on 2022/8/29.
//

#import "LGWeekdayCalendarCell.h"

@interface LGWeekdayCalendarCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *weekLabel;
/**   */
@property (nonatomic , strong)UILabel *dayLabel;

@property (nonatomic , strong)NSCalendar *calendar;

@end

@implementation LGWeekdayCalendarCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.baseView];
        [self.contentView addSubview:self.weekLabel];
        [self.contentView addSubview:self.dayLabel];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(1);
            make.centerX.equalTo(self.contentView);
            make.bottom.equalTo(self.dayLabel.mas_bottom).offset(viewPix(6));
            make.width.equalTo(@(viewPix(44)));
        }];
        [self.weekLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(10));
            make.centerX.equalTo(self.contentView);
        }];
        [self.dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.weekLabel.mas_bottom).offset(viewPix(6));
            make.centerX.equalTo(self.contentView);
            make.width.height.equalTo(@(viewPix(30)));
        }];
    }
    return self;
}

-(void)setDate:(NSDate *)date{
    _date = date;
    self.weekLabel.text = [LGCalculateTool weekdayWithDate:date];
    self.dayLabel.text =  @([self.calendar component:NSCalendarUnitDay fromDate:date]).stringValue;
}

-(void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
    self.baseView.hidden = !isSelected;
    if (isSelected == YES) {
        self.weekLabel.textColor = [UIColor colorWithString:@"#FFFFFF"];
        self.dayLabel.textColor = [UIColor colorWithString:@"#439779"];
       
    }else{
        self.weekLabel.textColor = [UIColor colorWithString:@"#9595A0"];
        self.dayLabel.textColor = [UIColor colorWithString:@"#2B2A37"];
    }
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]init];
        _baseView.backgroundColor = [UIColor colorWithString:@"439779"];
        _baseView.cornerRidus = viewPix(22);
        _baseView.hidden = YES;
    }
    return _baseView;
}

-(UILabel *)weekLabel{
    if(!_weekLabel){
        _weekLabel = [UILabel lableWithText:@"" colorString:@"FFFFFF"  textFont:LGFont(14) textAlignment:NSTextAlignmentCenter  lines:1];
    }
    return _weekLabel;
}

-(UILabel *)dayLabel{
    if(!_dayLabel){
        _dayLabel = [UILabel lableWithText:@"" colorString:@"FFFFFF" textFont:LGFontWeight(16, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
        _dayLabel.backgroundColor = [UIColor whiteColor];
        _dayLabel.cornerRidus = viewPix(15);
    }
    return _dayLabel;
}

-(NSCalendar *)calendar{
    if(!_calendar){
        _calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSTimeZone *timeZone = [[NSTimeZone alloc]initWithName:@"Asia/Beijing"];
        [_calendar setTimeZone: timeZone];
    }
    return _calendar;
}

@end
